package com.controller;

import java.util.HashMap;
import java.util.Map;








import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import com.model.User;
import com.service.ITestService;

@RestController  //不跳转页面只接受参数的传递与后台交互。
//@Controller  //传递参数同时页面进行返回跳转。
public class UserController {
	
		
		@Autowired
		ITestService testService;
		//@Autowired
		//IUserService userService;
		
		User user = new User();
		@RequestMapping(value="/home")
		public String home(Model m){
			System.err.println("****************88输出**************");
			//Map<String,String> map = new HashMap<>();
			//map.put("aaaa", "返回数据");
			//name = "zhang";
			//user.setName(name);
			m.addAttribute("name", "后台控制层返回到前台");
			//m.addAttribute("name", "spring-boot");
			//user.setName("赵志学");
			testService.queryUserList();
			return "hello";  
		}
		@RequestMapping(value="/saveAddAccountP",method=RequestMethod.POST)
		public void saveData(@RequestBody User u){
			//testService.queryUserList();
			//userService.queryUserList();
			System.err.println("*****"+u.toString());
		}
		@RequestMapping("hello")
	    public String hello(Model m){
	        m.addAttribute("name", "张晓明");
	        return "hello";
	    }
		@RequestMapping(value="/test")
		public ModelAndView testHello(@RequestParam String userid){
			//User user = userMapper.getUserById(userid);
			System.err.println("****"+userid);
			Map<String,User> modelMap = new HashMap<String,User>();
			user.setUserName("张晓明");
			modelMap.put("user", user);
			
			
			//modelMap.put("name", "aaaaa");
			System.err.println("**"+modelMap.toString());
			return new ModelAndView("hi",modelMap);		
		}
}
